﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace PIM_ATE.Mods
{
    public partial class FrmLogin : Form
    {
        public FrmLogin(ClsDataUser usr)
        {
            InitializeComponent();
            this.Text = "登陆";
            m_usrObj = usr;

            Assembly asm = Assembly.GetExecutingAssembly();
            var asmName = asm.GetName();
            this.Text = asmName.Version.ToString();
        }

        ClsDataUser m_usrObj;

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (!m_usrObj.verifyUser(textUser.Text, textPassword.Text))
            {
                MessageBox.Show(m_usrObj.sError);
                return;
            }

            if (checkMember.Checked)
            {
                IniFile.SetFileName(System.Windows.Forms.Application.StartupPath + "\\JcOther.ini");
                IniFile.IniWriteValue("Login", "User", textUser.Text);
            }
            else
            {
                IniFile.SetFileName(System.Windows.Forms.Application.StartupPath + "\\JcOther.ini");
                IniFile.IniWriteValue("Login", "User", "");
            }

            this.DialogResult = DialogResult.OK;
        }

        private void textBoxPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                BtnLogin_Click(sender, e);
            }
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            lblMac.Text = "测试设备:  " + m_usrObj.sEquID;
            IniFile.SetFileName(System.Windows.Forms.Application.StartupPath + "\\JcOther.ini");
            string user = IniFile.IniReadValue("Login", "User", "");
            if (user != "")
            {
                textUser.Text = user;
                checkMember.Checked = true;
            }
        }

        private void FrmLogin_Shown(object sender, EventArgs e)
        {
            if (checkMember.Checked)
            {
                textPassword.Focus();
            }
        }
    }
}
